<?php get_instance()->view('common/header');?>
<div class="page-container home">
    <?php get_instance()->view('common/sidebar');?>
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
                    <h3 class="page-title"> 订单管理 </h3>
                    <ul class="page-breadcrumb breadcrumb">
                        <li><i class="fa fa-home"></i><a href="javascript:void(0);">订单管理 </a></li>
                    </ul>
                    <!-- END PAGE TITLE & BREADCRUMB-->
                </div>
            </div>
            <div class="row">
                <div class="col-md-12">
                    <div class="portlet">
                        <div class="portlet-body">
                            <div class="table-container">
                                <div class="table-actions-wrapper"> <span> </span>
                                    <?php if(adminAuthority('home-export', 'order')):?>
                                        <a class="btn btn-sm blue add export" href="javascript:;"><i class="fa fa-download"></i> 导出</a>
                                    <?php endif;?>
                                </div>
                                <table class="table table-bordered table-hover" id="datatable">
                                    <thead>
                                        <tr role="row" class="heading">

                                            <th width="9%">订单号</th>
                                            <th width="4%">编号</th>
                                            <th width="9%">商家名称</th>
                                            <th width="6%">会员手机</th>
                                            <th width="9%">消费模式</th>
                                            <th width="7%">支付方式</th>
                                            <th width="7%">订单金额</th>
                                            <th width="7%">实付金额</th>
                                            <th width="9%">下单时间 </th>
                                            <th width="9%">支付时间 </th>
                                            <th width="15%">状态</th>
                                            <th width="9%">操作</th>
                                        </tr>
                                        <tr>
                                            <th><input class="form-control form-filter input-sm" name="orderCode" type="text"></th>
                                            <th><input class="form-control form-filter input-sm" name="merchant_day_index" type="text"></th>
                                            <th><input class="form-control form-filter input-sm" name="merchant" placeholder="" type="text"></th>
                                            <th><input class="form-control form-filter input-sm" name="consumer" placeholder="" type="text"></th>
                                            <th>
                                                <select name="expenseType" class="form-control form-filter input-sm">
                                                    <option value="" selected="selected">所有</option>
                                                    <?php foreach ($expenseType as $ke => $e):?>
                                                    <option value="<?php echo $ke;?>"><?php echo $e;?></option>
                                                    <?php endforeach;?>
                                                </select>
                                            </th>
                                            <th>
<!--                                                <select name="payType" class="form-control form-filter input-sm">-->
<!--                                                    <option value="" selected="selected">所有</option>-->
<!--                                                    --><?php //foreach ($payType as $k => $v):?>
<!--                                                        <option value="--><?php //echo $k+1;?><!--">--><?php //echo $v;?><!--</option>-->
<!--                                                    --><?php //endforeach;?>
<!--                                                </select>-->
                                                <select class="paytype form-control form-filter input-sm sel " multiple name="payArr[]" data-placeholder="请选择">
                                                    <?php foreach ($payType as $k=>$v): ?>
                                                        <?php if($k > 0):?>
                                                            <option value="<?php echo $k?>" ><?php echo $v?></option>
                                                        <?php endif;?>
                                                    <?php endforeach;?>
                                                </select>
                                            </th>
                                            <th>
                                                <div class="margin-bottom-5">
                                                    <input class="form-control form-filter input-sm" name="amount_from" placeholder="大于等于" type="text">
                                                </div>
                                                <input class="form-control form-filter input-sm" name="amount_to" placeholder="小于等于" type="text" ></th>
                                            </th>
                                            <th></th>
                                            <th>
                                               <div class="margin-bottom-5">
                                                    <input class=" form-control form-filter input-sm" name="add_time_from" dp placeholder="从" type="text">
                                               </div>
                                               <input class=" form-control form-filter input-sm" name="add_time_to" dp placeholder="到" type="text" ></th>
                                            </th>
                                            <th>
                                                <div class="margin-bottom-5">
                                                    <input class="datetimepicker form-control form-filter input-sm" name="pay_time_from"  placeholder="从" type="text">
                                                </div>
                                                <input class="datetimepicker form-control form-filter input-sm" name="pay_time_to"  placeholder="到" type="text" ></th>
                                            </th>
                                            <th>
<!--                                                <select name="orderStatus" class="form-control form-filter input-sm">-->
<!--                                                    --><?php //foreach ($status as $k => $v):?>
<!--                                                    <option value="--><?php //echo $k;?><!--">--><?php //echo $v;?><!--</option>-->
<!--                                                    --><?php //endforeach;?>
<!--                                                </select>-->
                                                <select class="orderStatus form-control form-filter input-sm sel" multiple name="statusArr[]" data-placeholder="请选择">
                                                    <?php foreach ($status as $k=>$v): ?>
                                                        <?php if($k > 0):?>
                                                            <option value="<?php echo $k?>" ><?php echo $v?></option>
                                                            <?php endif;?>
                                                    <?php endforeach;?>
                                                </select>
                                                <script type="text/javascript">
                                                    $(function () {
                                                        $(".sel").select2();
                                                    });
                                                </script>
                                            </th>
                                            <th>
                                                <div class="btn-group">
                                                    <a class="btn btn-xs filter-submit btn-default"><i class="fa fa-search"></i> 搜索</a>
                                                    <button data-toggle="dropdown" class="btn btn-default dropdown-toggle btn-xs" type="button"><i class="fa fa-angle-down"></i></button>
                                                    <ul role="menu" class="dropdown-menu pull-right">
                                                        <li><a href="javascript:void(0);" class="filter-cancel">重置</a></li>
                                                    </ul>
                                                </div>
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody></tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        datatable_init({
            src: $("#datatable"),
            sAjaxSource: "<?php echo getUrl('order/home/getList');?>",
            aoColumnDefs : [{
                'bSortable' : false,
                'aTargets' : [0,1,2,3,4,5,8,9,10,11]
            }]
        });

        $('.datetimepicker').datetimepicker({
            step: 60,
            format:    'yyyy-mm-dd hh:ii',
            yearStart: 2018,              // 设置最小的年份
            yearEnd: 2050,              // 设置最大的年份
            language: 'zh-CN'
        });

        $('[dp]').not("[noinit]").datepicker({
            changeMonth: true,
            autoclose: true,
            format: "yyyy-mm-dd",
            language: 'zh-CN'
        });

        $(".export").on('click',function () {
            var add_time_from = $("[name='add_time_from']").val();
            var add_time_to = $("[name='add_time_to']").val();
            var pay_time_from = $("[name='pay_time_from']").val();
            var pay_time_to = $("[name='pay_time_to']").val();
            var amount_from = $("[name='amount_from']").val();
            var amount_to = $("[name='amount_to']").val();
            var payType = '';
            var expenseType = $("[name='expenseType']").val();
            var consumer = $("[name='consumer']").val();
            var merchant = $("[name='merchant']").val();
            var orderCode = $("[name='orderCode']").val();
            var orderStatus = '';
            var len = $(".paytype").size();
            var slen = $(".orderStatus").size();

            if(len){
                $(".paytype").each(function () {
                    if($(this).val()){
                        payType = $(this).val();
                    }
                })
            }

            if(slen){
                $(".orderStatus").each(function () {
                    if($(this).val()){
                        orderStatus = $(this).val();
                    }
                })
            }

            var url = '';
            if(add_time_from.length){
                url = 'add_time_from='+add_time_from;
            }
            if(add_time_to.length){
                url += '&add_time_to='+add_time_to;
            }
            if(pay_time_from.length){
                url = '&pay_time_from='+pay_time_from;
            }
            if(pay_time_to.length){
                url += '&pay_time_to='+pay_time_to;
            }
            if(amount_from.length){
                url = '&amount_from='+amount_from;
            }
            if(amount_to.length){
                url += '&amount_to='+amount_to;
            }
            if(orderStatus){
                url += '&statusArr='+orderStatus;
            }

            if(payType){
                url += '&payArr='+payType;
            }
            if(expenseType.length){
                url += '&expenseType='+expenseType;
            }
            if(consumer.length){
                url += '&consumer='+consumer;
            }
            if(merchant.length){
                url += '&merchant='+merchant;
            }
            if(orderCode.length){
                url += '&orderCode='+orderCode;
            }
//                if (url.indexOf('&') == 0){
//                    url = url.substr(1,url.length);
//                }
            if (url.indexOf('&') == 0){
                url = url.substr(1,url.length);
            }
            if(url.length){
                window.location.href="<?php echo getUrl('order/home/export')?>?"+url;
            }else{
                window.location.href="<?php echo getUrl('order/home/export')?>";
            }
        })
    });
</script>
</body>
</html>